<!--DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"-->

<%@page import="acceso.util.WorkflowUtil"%>
<%@page import="sun.print.PSPrinterJob"%>
<%--<%@page import="org.apache.poi.hssf.record.formula.functions.Count"%>--%>
<%@page import="java.util.Enumeration"%>
<%@page import="acceso.beans.PagEspBean"%>
<%@page import="java.util.ArrayList" %>
<%@page import="acceso.util.Escritor"%>
<%@page import="wf.dto.pagesp.PaginaEspecialDto"%>

<%@page  language="java" contentType="text/html" pageEncoding="ISO-8859-1"%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
    <%
        String no_docume = "";
        int nu = -1;
        int max = 0;
        ArrayList<String> p = new ArrayList<String>();
        try {
            if (request.getAttribute("pag") != null) {
                PagEspBean pag = (PagEspBean) request.getAttribute("pag");
                String del = "[~]+";
                String[] params = null;
                String[][] req = new String[pag.getLs_parame().size()][2];
                for (int i = 0; i < pag.getLs_parame().size(); i++) {
                    params = pag.getLs_parame().get(i).split(del, 2);
                    req[i][0] = params[0];
                    if (params.length > 1) {
                        req[i][1] = params[1];
                    } else {
                        req[i][1] = "";
                    }
                }
                for (int i = 0; i < req.length; i++) {
                    nu = Integer.parseInt(req[i][0].substring(1));
                    if (nu > max) {
                        max = nu;
                    }
                }
                int aux = 0;
                int pos;
                while (p.size() <= max) {
                    pos = -1;
                    for (int i = 0; i < req.length; i++) {
                        if (Integer.parseInt(req[i][0].substring(1)) == aux) {
                            pos = i;
                        }
                    }
                    if (pos != -1) {
                        p.add(req[pos][1]);
                    } else {
                        p.add(null);
                    }
                    aux = aux + 1;
                }
                no_docume = pag.docume(pag.getCo_docume(), p);
            } else {
                Enumeration en = request.getParameterNames();
                while (en.hasMoreElements()) {
                    String paramName = (String) en.nextElement();
                    if (paramName.startsWith("p")) {
                        nu = Integer.parseInt(paramName.substring(1));
                        if (nu > max) {
                            max = nu;
                        }
                    }
                }
                p.add(null);
                for (int i = 1; i <= max; i++) {
                    p.add(request.getParameter("p" + i));
                }
                PagEspBean pag = new PagEspBean();
                no_docume = pag.docume(WorkflowUtil.convertir_entero(request.getParameter("co_docume")), p);
            }
        } catch (Exception e) {
            Escritor.escribe_errors(e.toString());
        }
    %>
    <%=no_docume %>
    <c:if test="${param.imprimir == 1}">
        <script>window.print();</script>
    </c:if>
</html>